package com.atguigu.srb.sms.receiver;

import com.atguigu.ronglianyun.sms.service.SmsService;
import com.atguigu.srb.base.dto.SmsDTO;
import com.atguigu.srb.rabbitutil.constant.MQConst;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class SmsReceiver {
    private SmsService smsService;

    public SmsReceiver(SmsService smsService) {
        this.smsService = smsService;
    }

    @RabbitListener(
            bindings = @QueueBinding(
                    value = @Queue(value = MQConst.QUEUE_SMS_ITEM, durable = "true"),
                    exchange = @Exchange(value = MQConst.EXCHANGE_TOPIC_SMS, type = ExchangeTypes.TOPIC),
                    key = {MQConst.ROUTING_SMS_ITEM}
            ))
    public void send(SmsDTO smsDTO) {
        log.info("SmsReceiver监听消息");
        String[] datas = new String[2];
        datas[0] = smsDTO.getMessage();
        datas[1] = "5";
        log.info(smsDTO.toString());
//        smsService.send(smsDTO.getMobile(), SmsProperties.TEMPLATE_CODE, datas);
    }
}
